<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="企业名称" name="companyName"/>
        <f-search-form-item label="审核状态" name="auditState" type="select" :data="api.company.authStatus"></f-search-form-item>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="companyId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.company">
        <span slot="companyLogo" slot-scope="text, record, index">
           <f-images :value="record.companyLogo"></f-images>
        </span>
        <span slot="companyName" slot-scope="text, record, index">
           <f-elipsis :text="record.companyName" :length="25"></f-elipsis>
        </span>
        <span slot="recommend" slot-scope="text, record, index">
          <a-switch v-model="record.recommend==1" checkedChildren="是" unCheckedChildren="否" @change="(checked) => setStatus(checked,record)"/>
        </span>
        <span slot="auditState" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==0">未认证</a-tag>
            <a-tag color="#108ee9" v-if="text==1">待审核</a-tag>
            <a-tag color="#87d068" v-if="text==2">已认证</a-tag>
            <a-tag color="#f50" v-if="text==10">已退回</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.companyId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <company-drawer ref="modal"></company-drawer>
    </a-card>
  </div>
</template>

<script>
  import CompanyDrawer from './company_drawer'
  export default {
    name: 'TableList',
    components: {
      CompanyDrawer,
      CompanyAudit: resolve => {
        require(['./company_audit.vue'], resolve)
      }
    },
    data() {
      let me = this
      return {
        //列表初始化查询参数
        queryParam: {},
        companyType: [{ value: 'SUPPLIER', label: '供应商' }, { value: 'DEVELOPER', label: '开发商' }, { value: 'CONSTRUCTOR', label: '施工方' }, { value: 'DESIGNER', label: '设计方' }, { value: 'HOTEL', label: '酒店管理' }],
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: 'Logo',
            align: 'center',
            scopedSlots: { customRender: 'companyLogo' }
          },
          {
            title: '企业名称',
            align: 'center',
            scopedSlots: { customRender: 'companyName' }
          },
          {
            title: '联系人',
            width: 100,
            align: 'center',
            dataIndex: 'linkMan'
          },
          {
            title: '联系电话',
            align: 'center',
            dataIndex: 'linkTel'
          },
          {
            title: '地址',
            align: 'center',
            dataIndex: 'companyAddress'
          },
          {
            title: '推荐',
            align: 'center',
            dataIndex: 'recommend',
            scopedSlots: { customRender: 'recommend' }
          },
          {
            title: '认证状态',
            align: 'center',
            dataIndex: 'auditState',
            scopedSlots: { customRender: 'auditState' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '180px',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
          {
            name: '添加',
            icon: 'plus',
            that: this,
            handler: function(table, that) {
              that.$refs.modal.handleShow()
            }
          },
          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function(table) {
              table.remove()
            }
          }
        ]
      }
    },
    created() {

    },
    methods: {
      setStatus(check, record) {
        this.http.post(this, {
          url: this.api.company.setRecommend,
          data: {
            ids: record.companyId,
            recommend: Number(check)
          },
          success(me, data) {
            record.recommend = data
          }
        })
      }
    }
  }
</script>
